home *** CD-ROM | disk | FTP | other *** search
- #include "MacLuff.h"
-
- /* The main program which administrate who's on the move etc */
-
- main(){
- int x, y;
- struct QDVar QDVar;
- DateTimeRec date_record;
-
- QD = &QDVar;
-
- /* Standard initialisation */
- InitGraf(&thePort);
- InitFonts();
- /* FlushEvents(everyEvent, 0); */
- InitWindows();
- InitMenus();
- /* TEInit(); */
- InitDialogs((ProcPtr) 0);
- InitCursor();
-
- /* Application dependent initialisation */
- init_the_w();
- SetPort(the_w);
- init_the_menu();
- h_curs = GetCursor(FINGER); finger = **h_curs;
-
- for(x = 0; x < XZIZE; x++)
- for(y = 0; y < YZIZE; y++)
- board[x][y] = ' ';
- done_flag = message_flag = FALSE;
-
- GetTime(&date_record);
- srand(date_record.second);
-
- while(TRUE){
- while(TRUE){
- if(Button())
- slf = FALSE;
- if(!slf)
- inmove(&x, &y); /* This is the main event loop */
- if(slf){
- if(playcnt){
- if(!chose('x', &x, &y)){
- draw_message("Can't find a place for my 'x'");
- break;
- }
- }
- else{
- x = XZIZE/2;
- y = YZIZE/2;
- }
- }
- play[x][y] = ++playcnt;
- draw_x(x, y);
- board[x][y] = 'x';
- if(update(x, y)){
- draw_message("Congratulations you won");
- break;
- }
- if(!chose('o', &x, &y)){
- draw_message("Can't find a place for my 'o'");
- break;
- }
- play[x][y] = ++playcnt;
- draw_o(x, y);
- board[x][y] = 'o';
- if(update(x, y)){
- draw_message("I won");
- break;
- }
- }
- DisableItem(my_menus[3], SHOW_GAME);
- DisableItem(my_menus[3], HINT);
- done_flag = TRUE;
- slf = FALSE;
- }
- }
-
- init_the_w(){
- int x, y;
-
- the_w = GetNewWindow(WINDOW, &w_record, (WindowPtr) -1);
-
- SetRect(&play_r, 0, 35, XZIZE*15, YZIZE*15 + 35);
- SetRect(&message_r, 0, 0, 450, 34);
- for(x = 0; x < XZIZE; x++)
- for(y = 0; y < YZIZE; y++)
- SetRect(&xy_r[x][y], x*15 - 1, y*15 + 34, x*15 + 15, y*15 + 50);
- SetRect(&hole_r[0], 130, 15, 140, 25);
- SetRect(&hole_r[1], 160, 15, 170, 25);
- SetRect(&hole_r[2], 270, 15, 280, 25);
- SetRect(&hole_r[3], 300, 15, 310, 25);
- }
-
- init_the_menu(){
- my_menus[0] = GetMenu(APPLE);
- InsertMenu(my_menus[0], 0);
-
- my_menus[1] = GetMenu(FILE);
- InsertMenu(my_menus[1], 0);
-
- my_menus[2] = GetMenu(HELP);
- InsertMenu(my_menus[2], 0);
-
- my_menus[3] = GetMenu(COMMAND);
- InsertMenu(my_menus[3], 0);
-
- DrawMenuBar();
- }
-